package com.ruoyi.bus.controller;

import java.util.Arrays;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bus.domain.StaffInfo;
import com.ruoyi.bus.service.IStaffInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 职工信息Controller
 *
 * @author ruoyi
 * @date 2020-04-09
 */
@Controller
@RequestMapping("/bus/staffInfo")
public class StaffInfoController extends BaseController {
    private String prefix = "bus/staffInfo";

    @Autowired
    private IStaffInfoService staffInfoService;

    @RequiresPermissions("bus:staffInfo:view")
    @GetMapping()
    public String staffInfo() {
        return prefix + "/staffInfo";
    }

            /**
         * 查询职工信息列表
         */
        @RequiresPermissions("bus:staffInfo:list")
        @PostMapping("/list")
        @ResponseBody
        public TableDataInfo list(StaffInfo staffInfo) {
            startPage();
            return getDataTable(staffInfoService.list(new QueryWrapper<>(staffInfo)));
        }
    
    /**
     * 导出职工信息列表
     */
    @RequiresPermissions("bus:staffInfo:export")
    @Log(title = "职工信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StaffInfo staffInfo) {
        List<StaffInfo> list = staffInfoService.list(new QueryWrapper<>(staffInfo));
        ExcelUtil<StaffInfo> util = new ExcelUtil<>(StaffInfo.class);
        return util.exportExcel(list, "staffInfo");
    }

            /**
         * 新增职工信息
         */
        @GetMapping("/add")
        public String add() {
            return prefix + "/add";
        }
    
    /**
     * 新增保存职工信息
     */
    @RequiresPermissions("bus:staffInfo:add")
    @Log(title = "职工信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StaffInfo staffInfo) {
        return toAjax(staffInfoService.save(staffInfo));
    }

    /**
     * 修改职工信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        StaffInfo staffInfo = staffInfoService.getById(id);
        mmap.put("staffInfo", staffInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存职工信息
     */
    @RequiresPermissions("bus:staffInfo:edit")
    @Log(title = "职工信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StaffInfo staffInfo) {
        return toAjax(staffInfoService.updateById(staffInfo));
    }

            /**
         * 删除职工信息
         */
        @RequiresPermissions("bus:staffInfo:remove")
        @Log(title = "职工信息", businessType = BusinessType.DELETE)
        @PostMapping( "/remove")
        @ResponseBody
        public AjaxResult remove(String ids) {
            return toAjax(staffInfoService.removeByIds(Arrays.asList(Convert.toStrArray(ids))));
        }
        }
